/*
 * Action.java
 *
 * Created on 28 sierpień 2007, 17:02
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package pl.krakow.ae.knp.wikiboard.xml;

import java.io.FileOutputStream;
import java.io.IOException;
import nu.xom.Attribute;
import nu.xom.Document;
import nu.xom.Element;
import nu.xom.Serializer;


/**
 *
 * @author Michał
 */
public class ActionXML {
    
    private UserXML user;
    private String type; 
    
    /** Creates a new instance of ActionXML */
    public ActionXML(UserXML user, String type) {
        this.user = user;
        this.type = type;
    }
    
    public Element getXML() {
        Element action = new Element("action");
        Attribute aType = new Attribute("type",type);
        action.addAttribute(aType);
        Element eUser = user.getXML();
        action.appendChild(eUser);
        return action;
    }
    
    public static void main(String[] args) {     
        
        UserXML u = new UserXML(21,"kuzynka Chmurka",false);
        ActionXML a = new ActionXML(u,"login");
        
        Document doc = new Document(a.getXML());
        try {
            Serializer serializer = new Serializer(new FileOutputStream("c:\\doc.xml"));
            serializer.setIndent(4);
            serializer.write(doc);
        } catch(IOException ex) {
            System.err.println(ex);
        }
    }
}
